<?php

namespace IDock\Insurance\JDAL\Request;

use Exception;
use IDock\Insurance\JDAL\Bean\BasePremiumInquiry;
use IDock\Insurance\JDAL\Response\VehicleInsureQueryResponse;
use IDock\Visitor\Premium\PremiumInquiryVisitor;

class VehicleInsureQueryRequest extends AllJDALRequest
{
    public $route = 'quote/insureQuery';

    public $requestCode = 'insureQueryServiceRequest';

    protected $response = VehicleInsureQueryResponse::class;

    protected $urlTip = '方案查询';

    public $callFrom;

    /*** @var  PremiumInquiryVisitor $visitor */
    protected $visitor;

    /*** @var BasePremiumInquiry $basePremiumInquiry */
    public $basePremiumInquiry;

    /**
     * @return array
     * @throws Exception
     */
    public function generate(): array
    {
        $this->partnerRef = $this->basePremiumInquiry->partnerRef;

        return [
            'basePart' => $this->basePart(),
            'vehicle' => $this->vehicle(),
            'owner' => $this->basePremiumInquiry->owner,
            'coverageItems' => $this->basePremiumInquiry->coverageItemList,
            'vehicleTaxation' => $this->basePremiumInquiry->vehicleTaxation,
        ];
    }

    /**
     * 基本信息
     * @return array
     */
    private function basePart(): array
    {
        $basePart = $this->basePremiumInquiry->basePart;

        $basePart['callFrom'] = $this->callFrom;
        $basePart['systemSource'] = 'CAR_API';

        return $basePart;
    }

    /**
     * 车辆信息
     * @return array
     */
    private function vehicle(): array
    {
        $vehicle = $this->basePremiumInquiry->vehicle;

        //$vehicle['fuelTypeBj'] = '';
        //$vehicle['salesChannelCode'] = '';

        $vehicle['commVehSubtype'] = $this->basePremiumInquiry->commVehSubtype;
        $vehicle['vehicleStyleUniqueId'] = $this->visitor->getVehicleVisitor()->argc['vehicleStyleUniqueId'] ?? '';

        return $vehicle;
    }
}
